﻿using System;

using Elifart.Library.Utils;

namespace Elifart.Library
{
    public class Association
    {
        #region Constructor

        public Association()
        {
            this.GUID = Guid.NewGuid().ToString();
            this.AffiliationGUID = string.Empty;
        }

        public Association(string associationName,
                                   string abbreviation,
                                   DateTime foundingDate,
                                   string flagName,
                                   string affiliationGUID,
                                   AssociationCollection members) : this()
        {
            this.Name = associationName;
            this.Abbreviation = abbreviation;
            this.FoundingDate = foundingDate;
            this.FlagName = flagName;
            this.AffiliationGUID = affiliationGUID;
            this.Members = members;
        }

        #endregion

        #region Attributes and Properties

        private string _GUID;
        public string GUID
        {
            get 
            {
                if (this._GUID == null)
                    this._GUID = Guid.NewGuid().ToString();
                return this._GUID; 
            }
            set
            {
                this._GUID = value;
                this.Notifier.RaisePropertyChanged("GUID");
            }
        }

        private string _name;
        public string Name
        {
            get { return this._name; }
            set 
            {
                this._name = value;
                this.Notifier.RaisePropertyChanged("Name");
            }
        }

        private string _abbreviation;
        public string Abbreviation
        {
            get { return this._abbreviation; }
            set
            {
                this._abbreviation = value;
                this.Notifier.RaisePropertyChanged("Abbreviation");
            }
        }

        private DateTime _foundingDate;
        public DateTime FoundingDate
        {
            get { return this._foundingDate; }
            set 
            {
                this._foundingDate = value;
                this.Notifier.RaisePropertyChanged("FoundingDate");
            }
        }

        private string _flagName;
        public string FlagName
        {
            get { return this._flagName; }
            set 
            {
                this._flagName = value;
                this.Notifier.RaisePropertyChanged("FlagName");
            }
        }

        private string _affiliationGUID;
        public string AffiliationGUID
        {
            get { return this._affiliationGUID; }
            set 
            {
                this._affiliationGUID = value;
                this.Notifier.RaisePropertyChanged("AffiliationGUID");
            }
        }

        private AssociationCollection _members;
        public AssociationCollection Members
        {
            get 
            {
                if (this._members == null)
                    this._members = new AssociationCollection();
                return this._members; 
            }
            set 
            { 
                this._members = value;
                this.Notifier.RaisePropertyChanged("Members");
            }
        }

        [NonSerialized]
        private ChangesNotifier<Association> _notifier;
        public ChangesNotifier<Association> Notifier
        {
            get 
            { 
                if (this._notifier == null)
                    this._notifier = new ChangesNotifier<Association>(this);
                return this._notifier;
            }
        }

        #endregion

        #region Overriden Methods

        public override string ToString()
        {
            return this.Abbreviation;
        }

        #endregion
    }
}
